#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <jni.h>


//#include "rfcardinf.h"
#include "utiledef.h"

#include "iccrf.h"
#include "serialportapi.h"

#include "com_device_RFcard.h"




//----------------------------------------------------------------------------------------------------------
//读卡器接口
//----------------------------------------------------------------------------------------------------------
//��ʼ�������ö˿�
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1init (JNIEnv *env, jclass thiz, jint port, jlong baud)
{
	int result = -1;
    //Device_Drv_Reset();
	result=rf_init(0,baud);

	return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1get_1status(JNIEnv *env , jclass thiz, jint icdev, jbyteArray ba)
{
    int result = -1;
    jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, ba, NULL);
    result=rf_get_status(icdev,tempserial_nm);
    (*env)->ReleaseByteArrayElements(env, ba, tempserial_nm, 0);
    return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1lib_1ver(JNIEnv *env, jclass thiz, jbyteArray ver)
{

    int result = -1;
    jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, ver, NULL);

    //strcpy(tempserial_nm,"ver 1.0 2019-06-21");
    rf_lib_ver(tempserial_nm);
    (*env)->ReleaseByteArrayElements(env, ver, tempserial_nm, 0);
    return 0;

}

//
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1exit(JNIEnv *env, jclass thiz, jint icdev)
{
	return rf_exit(icdev);
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1findcard(JNIEnv *env, jclass thiz, jint icdev, jbyte wmode, jbyteArray len, jbyteArray serial_nm)
{
	int result = -1;

	jbyte* templen = (*env)->GetByteArrayElements(env, len, NULL);
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, serial_nm, NULL);

	result= rf_ISO14443A_findcard(icdev,wmode,templen,tempserial_nm);

	(*env)->ReleaseByteArrayElements(env, len, templen, 0);
	(*env)->ReleaseByteArrayElements(env, serial_nm, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_ISO14443A_ATS
 * Signature: (I[B[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1ATS(JNIEnv *env, jclass thiz, jint icdev, jbyteArray len , jbyteArray rats)
{
	int result = -1;
	jbyte* templen = (*env)->GetByteArrayElements(env, len, NULL);
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, rats, NULL);
	result = rf_ISO14443A_ATS(icdev,templen,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, len, templen, 0);
	(*env)->ReleaseByteArrayElements(env, rats, tempserial_nm, 0);
	return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1select(JNIEnv *env, jclass thiz , jint icdev, jbyte mode, jbyteArray csn)
{
	int result = -1;

	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, csn, NULL);
	result = rf_ISO14443A_select(icdev,mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, csn, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_ISO14443A_APDU
 * Signature: (IB[B[B[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1APDU
  (JNIEnv *env, jclass thiz, jint icdev, jbyte  slen, jbyteArray sbuf, jbyteArray rlen, jbyteArray rbuf)
{
	jint result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, sbuf, NULL);
	jbyte* templen2 = (*env)->GetByteArrayElements(env, rlen, NULL);
	jbyte* tempserial_nm2 = (*env)->GetByteArrayElements(env, rbuf, NULL);
	result = rf_ISO14443A_APDU(icdev,slen,tempserial_nm,templen2,tempserial_nm2);
	(*env)->ReleaseByteArrayElements(env, sbuf, tempserial_nm, 0);
	(*env)->ReleaseByteArrayElements(env, rlen, templen2, 0);
	(*env)->ReleaseByteArrayElements(env, rbuf, tempserial_nm2, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_des_1code (JNIEnv *env, jclass thiz, jbyte mode , jbyteArray indata, jbyteArray inkey, jbyteArray outdata)
{
	int result = -1;
	//LOGE("test rf_card");
	jbyte* temp_indata= (*env)->GetByteArrayElements(env, indata, NULL);
	jbyte* temp_inkey = (*env)->GetByteArrayElements(env, inkey, NULL);
	jbyte* temp_outdata = (*env)->GetByteArrayElements(env, outdata, NULL);

	result=des_code(mode,temp_indata,temp_inkey,temp_outdata);

	(*env)->ReleaseByteArrayElements(env, outdata, temp_outdata, 0);

	return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_des3_1code (JNIEnv *env, jclass thiz, jbyte mode , jbyteArray indata, jbyteArray inkey, jbyteArray outdata)
{
	int result = -1;
	//LOGE("test rf_card");
	jbyte* temp_indata= (*env)->GetByteArrayElements(env, indata, NULL);
	jbyte* temp_inkey = (*env)->GetByteArrayElements(env, inkey, NULL);
	jbyte* temp_outdata = (*env)->GetByteArrayElements(env, outdata, NULL);

	result=des3_code(mode,temp_indata,temp_inkey,temp_outdata);

	(*env)->ReleaseByteArrayElements(env, outdata, temp_outdata, 0);

	return result;
}
/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_ISO14443A_Deselect
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1Deselect (JNIEnv *env, jclass thiz, jint icdev)
{
	return rf_ISO14443A_Deselect(icdev);
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1card(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jlongArray _Snr){
	int result = -1;
	//LOGE("test rf_card");
	jlongArray* tempserial_nm = (*env)->GetLongArrayElements(env, _Snr, NULL);
	result = rf_card(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseLongArrayElements(env, _Snr, tempserial_nm, 0);

	return result;


}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_config
 * Signature: (IBB)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1config(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyte _Baud)
{
	return rf_config(icdev,_Mode ,_Baud);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_request
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1request
  (JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray TagType){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, TagType, NULL);
	result = rf_request(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, TagType, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_anticoll
 * Signature: (IB[J)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1anticoll
  (JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray sn){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, sn, NULL);
	result = rf_anticoll(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, sn, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_select
 * Signature: (IJ[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1select
  (JNIEnv *env, jclass thiz, jint icdev, jbyteArray sn, jbyteArray TagType){
	int result = -1;
	uint32_t tmplong_sn;
    jbyte* temp_sn = (*env)->GetByteArrayElements(env, sn, NULL);
    jbyte* temp_TagType = (*env)->GetByteArrayElements(env, TagType, NULL);

    tmplong_sn=(uint8_t)(temp_sn[3]&0xff);
    tmplong_sn=(tmplong_sn<<8)+((uint8_t)(temp_sn[2]&0xff));
    tmplong_sn=(tmplong_sn<<8)+((uint8_t)(temp_sn[1]&0xff));
    tmplong_sn=(tmplong_sn<<8)+((uint8_t)(temp_sn[0]&0xff));
	LOGD("tmplong_sn  %X %X %X %X %X",temp_sn[0],temp_sn[1],temp_sn[2],temp_sn[3],tmplong_sn);

	result = rf_select(icdev,tmplong_sn,temp_TagType);
//	(*env)->ReleaseByteArrayElements(env,TagType, tempserial_nm, 0);
	(*env)->ReleaseByteArrayElements(env, TagType, temp_TagType, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_load_key
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1load_1key
  (JNIEnv *env, jclass thiz, jint icdev,  jbyte b1, jbyte b2, jbyteArray bs){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, bs, NULL);
	result = rf_load_key(icdev,b1,b2,tempserial_nm);
	//(*env)->ReleaseByteArrayElements(env, bs, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_load_key_hex
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1load_1key_1hex
(JNIEnv *env, jclass thiz, jint icdev,  jbyte b1, jbyte b2, jbyteArray bs){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, bs, NULL);
	result = rf_load_key_hex(icdev,b1,b2,tempserial_nm);
	//(*env)->ReleaseByteArrayElements(env, bs, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_halt
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1halt
  (JNIEnv *env, jclass thiz, jint icdev){
	return rf_halt(icdev);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_read
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1read
(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray TagType){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, TagType, NULL);
	result = rf_read(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, TagType, tempserial_nm, 0);
	return result;
}


/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_read_hex
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1read_1hex
(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray TagType){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, TagType, NULL);
	result = rf_read_hex(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, TagType, tempserial_nm, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_write
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1write
(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray TagType){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, TagType, NULL);
	result = rf_write(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, TagType, tempserial_nm, 0);
	return result;
}



JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1write_1hex
(JNIEnv *env, jclass thiz, jint icdev, jbyte _Mode, jbyteArray TagType){
	int result = -1;
	jbyte* tempserial_nm = (*env)->GetByteArrayElements(env, TagType, NULL);
	result = rf_write_hex(icdev,_Mode,tempserial_nm);
	(*env)->ReleaseByteArrayElements(env, TagType, tempserial_nm, 0);
	return result;
}

 
 

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1rfinf_1reset
  (JNIEnv *env, jclass thiz, jint icdev, jbyte s)
{
	int result = -1;

	result=rf_rfinf_reset(icdev,s);

	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_authentication
 * Signature: (IBB)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1authentication
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1,jbyte b2){
	return rf_authentication(icdev,b1,b2);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_changeb3
 * Signature: (IB[BBBBBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1changeb3
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b1,jbyteArray ba1, jbyte b2, jbyte b3, jbyte b4, jbyte b5, jbyte b6, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = rf_changeb3(icdev,b1,ba1,b2,b3,b4,b5,b6,ba2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_initval
 * Signature: (IBJ)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1initval
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b,jlong l){
	return rf_initval(icdev,b,l);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_increment
 * Signature: (IBJ)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1increment
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b,jlong l){
	return rf_increment(icdev,b,l);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_decrement
 * Signature: (IBJ)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1decrement
(JNIEnv * env, jclass thiz, jint icdev, jbyte b,jlong l){
	return rf_decrement(icdev,b,l);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_readval
 * Signature: (IB[J)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1readval
(JNIEnv * env, jclass thiz, jint icdev, jbyte b,jlongArray la){
	jbyte* cl = (*env)->GetLongArrayElements(env, la, NULL);
	int result = rf_readval(icdev,b,cl);
	(*env)->ReleaseLongArrayElements(env, la, cl, 0);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_restore
 * Signature: (IB)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1restore
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1){
	return rf_restore(icdev,b1);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_transfer
 * Signature: (IB)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1transfer
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1){
	return rf_transfer(icdev,b1);
}




/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_reset
 * Signature: (I[J[B)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1reset
        (JNIEnv * env, jclass thiz, jint icdev, jlongArray la1, jbyteArray la2){
    int result = -1;
    jlong* cl1 = (*env)->GetLongArrayElements(env, la1, NULL);
    jlong* cl2 = (*env)->GetLongArrayElements(env, la2, NULL);
    result =cpu_reset(icdev,cl1,cl2);
    (*env)->ReleaseLongArrayElements(env, la1, cl1, 0);
    (*env)->ReleaseLongArrayElements(env, la2, cl2, 0);
    return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_power_off
 * Signature: (I)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1power_1off
        (JNIEnv * env, jclass thiz, jint icdev){
    return cpu_power_off(icdev);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_access
 * Signature: (IB[B[B[B)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1access
        (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1, jbyteArray ba2, jbyteArray ba3){
    jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
    jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
    jbyte* cb3 = (*env)->GetByteArrayElements(env, ba3, NULL);
    int result = cpu_access(icdev,b,cb1,cb2,cb3);
    (*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
    (*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
    (*env)->ReleaseByteArrayElements(env, ba3, cb3, 0);
    return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_selsocket
 * Signature: (IB)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1selsocket
        (JNIEnv * env, jclass thiz, jint icdev, jbyte b){
    return cpu_selsocket(icdev,b);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_getsocket
 * Signature: (I[B)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1getsocket
        (JNIEnv * env, jclass thiz, jint icdev, jbyteArray ba){
    jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
    int result = cpu_getsocket(icdev,cb1);
    (*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
    return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    cpu_reset2
 * Signature: (IBB[J[B)J
 */
JNIEXPORT jlong JNICALL Java_com_device_RFcard_cpu_1reset2
        (JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jlongArray la, jbyteArray ba){
    jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
    jbyte* cl = (*env)->GetLongArrayElements(env, la, NULL);
    int result = cpu_reset2(icdev,b1,b2,cb1,cl);
    (*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
    (*env)->ReleaseLongArrayElements(env, cl, la, 0);
    return result;
} 


JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1init_1125KCard
  (JNIEnv * env, jclass thiz, jint icdev,jlong l){
	return rf_init_125KCard(icdev,l);
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_read_125Card_hex
 * Signature: (I[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1read_1125Card_1hex
(JNIEnv * env, jclass thiz, jint icdev, jbyteArray ba){
	int result = -1;
	jbyte* jb = (*env)->GetByteArrayElements(env, ba, NULL);
	result =rf_inputIO(icdev,jb);
	(*env)->ReleaseByteArrayElements(env, ba, jb, 0);
	return result;
} 

JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Inventory
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyte b3, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = ISO15693_Inventory(icdev,b1,b2,b3,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Stay_1Quiet
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Stay_Quiet(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Read
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyte b3, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = ISO15693_Read(icdev,b1,b2,b3,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Write
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyte b3, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = ISO15693_Write(icdev,b1,b2,b3,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Lock_1Block
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Lock_Block(icdev,b1,b2,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Select
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Select(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Reset_1To_1Ready
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Reset_To_Ready(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Write_1AFI
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Write_AFI(icdev,b1,b2,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Lock_1AFI
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Lock_AFI(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Write_1DSFID
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Write_DSFID(icdev,b1,b2,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Lock_1DSFID
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Lock_DSFID(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1GET_1System_1Information
(JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = ISO15693_GET_System_Information(icdev,b,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1GetMultipleBlockSecurity
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyte b3, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = ISO15693_GetMultipleBlockSecurity(icdev,b1,b2,b3,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}


JNIEXPORT jint JNICALL Java_com_device_RFcard_ISO15693_1Generic
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = ISO15693_Generic(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}



/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_ISO14443A_request
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1request
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	int result = rf_ISO14443A_request(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_ISO14443A_anticoll
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1ISO14443A_1anticoll
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	int result = rf_ISO14443A_anticoll(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_UL_findcard
 * Signature: (IB[B[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1UL_1findcard
(JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1, jbyteArray ba2){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	jbyte* cb2 = (*env)->GetByteArrayElements(env, ba2, NULL);
	int result = rf_UL_findcard(icdev,b,cb1,cb2);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	(*env)->ReleaseByteArrayElements(env, ba2, cb2, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_UL_read
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1UL_1read
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba1){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
	int result = rf_UL_read(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_UL_write
 * Signature: (IB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1UL_1write
  (JNIEnv * env, jclass thiz, jint icdev, jbyte b, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = rf_UL_write(icdev,b,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_UL_readM
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1UL_1readM
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = rf_UL_readM(icdev,b1,b2,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_UL_writeM
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1UL_1writeM
(JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba){
	jbyte* cb1 = (*env)->GetByteArrayElements(env, ba, NULL);
	int result = rf_UL_writeM(icdev,b1,b2,cb1);
	(*env)->ReleaseByteArrayElements(env, ba, cb1, 0);
	return result;
}


/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_readM
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1readM
        (JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba1){
    jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
    int result = rf_readM(icdev,b1,b2,cb1);
    (*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
    return result;
}

/*
 * Class:     com_yuwei_utils_ModuleControl
 * Method:    rf_writeM
 * Signature: (IBB[B)I
 */
JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1writeM
        (JNIEnv * env, jclass thiz, jint icdev, jbyte b1, jbyte b2, jbyteArray ba1){
    jbyte* cb1 = (*env)->GetByteArrayElements(env, ba1, NULL);
    int result = rf_writeM(icdev,b1,b2,cb1);
    (*env)->ReleaseByteArrayElements(env, ba1, cb1, 0);
    return result;
}

JNIEXPORT jint JNICALL Java_com_device_RFcard_rf_1HL_1authentication
        (JNIEnv *env, jclass thiz, jint icdev,jbyte reqmode, jlong snr,jbyte authmode,jbyte secnr)
{
    int result = -1;

    result=rf_HL_authentication(icdev,reqmode,snr,authmode,secnr);

    return result;
}

